import IPairTxData from '~/models/IData'
import IPlugin from './IPlugin'
import { parseWETHtoETH, fixed } from '~/util'

export default class SwapColPlugin implements IPlugin{

    public name = 'SwapCol'

    async modData(data: IPairTxData) {
        if (data.mints.length == 0) {
            return data
        }
        const pair = data.mints[0].pair
        const token0 = parseWETHtoETH(pair.token0.symbol)
        const token1 = parseWETHtoETH(pair.token1.symbol)

        const mints = data.mints
        const burns = data.burns
        const swaps = data.swaps

        for (let i = 0; i < mints.length; i++) {
            mints[i].tokenCol0 = `${fixed(mints[i].amount0)} ${token0}`
            mints[i].tokenCol1 = `${fixed(mints[i].amount1)} ${token1}`
        }
        for (let i = 0; i < burns.length; i++) {
            burns[i].tokenCol0 = `${fixed(burns[i].amount0)} ${token0}`
            burns[i].tokenCol1 = `${fixed(burns[i].amount1)} ${token1}`
        }
        for (let i = 0; i < swaps.length; i++) {
            if (parseFloat(swaps[i].amount0In) > 0 && parseFloat(swaps[i].amount1In) == 0) {
                // swaps[i].swapName = `swap ${token0} for ${token1}`
                swaps[i].tokenCol0 = `${fixed(swaps[i].amount0In)} ${token0}`
                swaps[i].tokenCol1 = `${fixed(swaps[i].amount1Out)} ${token1}`
            }
            else if (parseFloat(swaps[i].amount1In) > 0 && parseFloat(swaps[i].amount0In) == 0) {
                // swaps[i].swapName = `swap ${token1} for ${token0}`
                swaps[i].tokenCol0 = `${fixed(swaps[i].amount1In)} ${token1}`
                swaps[i].tokenCol1 = `${fixed(swaps[i].amount0Out)} ${token0}`
            }
        }
        return data
    }
}